<!-- header start -->
    <div class="header-transparent">
        <!-- navigation start -->
        <div class="container-fluid">
            <div class="row">
                <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                    <nav class="navbar navbar-expand-lg  navbar-transparent" id="Dheader">
                        <a class="navbar-brand" href="/"> <img src="<?= \common\services\DomainExtraConfigService::getVal('logoPath');?>" alt="<?= \common\services\DomainExtraConfigService::getVal('name');?>" style="height:50px;"></a>
                        <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbar-transparent" aria-controls="navbar-transparent" aria-expanded="false" aria-label="Toggle navigation">
                            <span class="icon-bar top-bar mt-0"></span>
                            <span class="icon-bar middle-bar"></span>
                            <span class="icon-bar bottom-bar"></span>
                        </button>
                        <div class="collapse navbar-collapse" id="navbar-transparent">
                            <ul class="navbar-nav ml-auto mt-2 mt-lg-0 mr-3">
                                <li class="nav-item">
                                    <a class="nav-link active" href="index" >
                                        首页
                                    </a>
                                    
                                </li>
								<li class="nav-item">
                                    <a class="nav-link" href="product" >
                                        功能简介
                                    </a>
                                    
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" href="download" >
                                        下载
                                    </a>
                                    
                                </li>
								<li class="nav-item">
                                    <a class="nav-link" href="help" >
                                        常见问题
                                    </a>
                                </li>
								
								
								<li class="nav-item">
                                    <a class="nav-link" href="contact" >
                                        联系我们
                                    </a>
                                </li>
							</ul>
                            <div class="header-btn" v-if="logined">
                                <a href="/tally" class="btn btn-warning btn-sm">记一笔</a>
                            </div>
                            <div class="header-btn" v-if="logined">
                                <a href="/personal" class="btn btn-info btn-sm">个人中心</a>
                            </div>
                            <div class="header-btn" v-if="logined">
                                <a href="javascript:;" class="btn btn-light btn-sm" v-on:click="logout">安全退出</a>
                            </div>
                            <div class="header-btn" v-if="!logined">
                                <a href="register" class="btn btn-danger btn-sm">立即注册</a>
                            </div>
                            <div class="header-btn" v-if="!logined">
                                <a href="login" class="btn btn-secondary btn-sm">登 陆</a>
                            </div>
                        </div>
                    </nav>
                </div>
            </div>
        </div>
        <!-- navigation close -->
    </div>
    <!-- header close -->
    <script>
    var logined = true
    var activeTab = '<?php echo $this->params['activeTab'];?>'
    new Vue({
        el: '#Dheader',
        data(){
            return {
                activeTab:activeTab,
                logined:false,
                userData:{}
            }
        },
        mounted() {
            this._initLogin();
        },
        methods: {
            _initLogin (){
                var loginToken  =  localStorage.getItem('loginToken');
                if(loginToken != null ){
                    // 调用token获取
                    this.getUserByToken(loginToken);
                }else{
                    localStorage.removeItem('userInfo');
                    logined = false
                }
            },
            getUserByToken(token) {
                let that = this;
                axios.get('/api/user/get-info',{
                    method: 'get',
                    headers: {'token': token},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        // 存入本地存储
                        var userData = res.data.data;
                        localStorage.setItem('userInfo',JSON.stringify(userData));
                        that.showUserData(userData);
                        logined = true
                    }else{
                        that.$message({
                            type: 'error',
                            message: '登录信息已失效~请重新登录'
                        });
                        localStorage.removeItem('userInfo');
                        localStorage.removeItem('loginToken');
                        setTimeout(function () {
                            window.location.href='/login';
                        },1000)
                    }
                    console.log(res);
                });
            },
            showUserData(userData) {
                this.logined = true ;
                this.userData = userData;
            },
            logout(){
                let that = this
                let loginToken  =  localStorage.getItem('loginToken');
                axios.get('/api/user/logout',{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    that.$message({
                        type: 'success',
                        message: '退出成功~跳转中...'
                    });
                    localStorage.removeItem('userInfo');
                    localStorage.removeItem('loginToken');
                    setTimeout(function () {
                        window.location.href='/';
                    },1000)
                });
            }
        }
    })
</script>
